package houtaiDao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;

import HoutaiUtil.MybatisUtil;
import Model.Shangpin;

public class ShangpinDaoImpl implements ShangpingDao {
	
	@Override
	public List<Shangpin> selectAll() {
		MybatisUtil mybat = new MybatisUtil();
		SqlSession session = mybat.mbtutil();
		List<Shangpin> list = session.selectList("houtaiDao.ShangpingDao.selectAll");
		session.close();
		return list;
	}

	@Override
	public int InsertShang(Map map) {
		MybatisUtil mybat = new MybatisUtil();
		SqlSession session = mybat.mbtutil();
		int flag = session.insert("houtaiDao.ShangpingDao.InsertShang",map);
		session.commit();
		session.close();	
		return flag;
	}

	@Override
	public int delS(int bianhao) {
		MybatisUtil mybat = new MybatisUtil();
		SqlSession session = mybat.mbtutil();
		int flag = session.delete("houtaiDao.ShangpingDao.delS",bianhao);
		session.commit();
		session.close();
		return flag;
	}

	@Override
	public Shangpin selOne(int bianhao) {
		MybatisUtil mybat = new MybatisUtil();
		SqlSession session = mybat.mbtutil();
		Shangpin sp = session.selectOne("houtaiDao.ShangpingDao.selOne", bianhao);
		session.close();
		return sp;
	}

	@Override
	public int update(Map map) {
		MybatisUtil mybat = new MybatisUtil();
		SqlSession session = mybat.mbtutil();
		int flag = session.update("houtaiDao.ShangpingDao.update",map);
		session.commit();
		session.close();
		return flag;
	}

	@Override
	public int del(int shopid) {
		MybatisUtil mybat = new MybatisUtil();
		SqlSession session = mybat.mbtutil();
		int flag = session.update("houtaiDao.ShangpingDao.del",shopid);
		session.commit();
		session.close();	
		return flag;
	}

}
